define(function(require, exports, module) {
    var router = require("router");
    //var app = require("app");
    var controller = {};
    controller.vue = function() {
        controller.vm = new Vue({
            router: router,
            data: function() {
                return {  
                   data:'',
                   mainorder:{}
                };
            },
            el: '#pageOrderDetail',
            created: function() {
                this.fetchData();
            },
            methods: {
                fetchData: function() {
                    this.loadOrder();
                    
                } ,
                loadOrder(reload = 0) {
                  var that = this;
                  if (reload == 1) {
                     that.data = {};
                  }
                  this.loading = 1;
                  app.get("mall/order/find", {
                    order_sn: this.$route.params.order_sn
                  }, function (res) {
                    that.loading = 0;
                    if (res.code != 200) {
                      app.alert(res.msg);
                      return;
                    }
                    that.data= res.data;
                     
                  });

                   app.get("apiv2/order/find", {
                    order_sn: this.$route.params.order_sn
                  }, function (res) {
                    that.loading = 0;
                    if (res.code != 200) {
                      app.alert(res.msg);
                      return;
                    }
                    that.mainorder= res.data;
                     
                  });
                }, 
                topay:function(order_sn){
                  app.pay(order_sn);
                },
                   //打开商家所在地点
                openlocation:function(){
                  if(!app.isWeiXin()){
                       return ;
                     }
                   var that = this;
                    app.wxJs(function(wx) {
                        wx.openLocation({
                          latitude: Number(that.mainorder.shop.latitude),
                          longitude: Number(that.mainorder.shop.longitude),
                          scale: 28,
                          address: that.mainorder.shop.fulladdress,
                          name: that.mainorder.shop.name,
                        });
                  });
                }


 
            }

        }).$mount('#app');
    };
    module.exports = controller;
});
